package sg.edu.nus.iss.vmcs.system;

import java.util.ArrayList;

import sg.edu.nus.iss.vmcs.abstraction.ICoinReceiverService;
import sg.edu.nus.iss.vmcs.abstraction.IStoreService;
import sg.edu.nus.iss.vmcs.store.Coin;

public class CoinReceiverService implements ICoinReceiverService
{    
    
    ArrayList<Coin> coins = new ArrayList<Coin>();
    
    @Override
    public void receive(Coin coin){
	coins.add(coin);
    }
    
    @Override
    public double refund(){
	int cash  = 0;
	for(Coin c : coins){
	    cash += c.getValue();
	}
	
	return  cash / 100.0;
    }
    
    @Override
    public void storeCash(){
	IStoreService storeService = ServiceRepository.GetInstance().getService(IStoreService.class);
	for(Coin c : coins){
	    storeService.storeCoin(c);
	}	
    }
    
    @Override
    public void reset(){
	coins.clear();
    }
}
